package com.paulianer.stuff;

import com.paulianer.interfaces.UDP_Packet;

public class MAGIC_PACKET implements UDP_Packet {
	private byte[] mp;
	private byte[] mac;
	private String ip;
	private int port;
	
	public MAGIC_PACKET(String mac, String ip, int port) {
		this.ip = ip;
		this.mac = mac2byte(mac);
		this.port = port;
		this.mp = createMP(this.mac);
	}
	
	private static byte[] mac2byte(String in) {
        byte[] retValue = new byte[6];
        String[] hex = in.split("(\\:|\\-)");
        for (int i = 0; i < hex.length; i++) {
        	retValue[i] = (byte)Integer.parseInt(hex[i], 16);
        }
        return retValue;
    }
	
	private static byte[] createMP(byte[] mac) {
		byte[] mp = new byte[102];
		for(int i = 0; i < 6; i++) {
			mp[i] = (byte) 0xFF;
		}
		for(int i = 6; i < 102; i++) {
			mp[i] = mac[i%6];
		}
		return mp;
	}

	public String getIP() {
		return this.ip;
	}

	public byte[] getCONTENT() {
		return this.mp;
	}
	
	public int getPort() {
		return this.port;
	}
	
	public static void main(String[] args) {
		MAGIC_PACKET mp = new MAGIC_PACKET("12:12:12:12", "1.1.1.1", 9);
		System.out.println (mp.getCONTENT());
		System.out.println("Laenge: "+mp.getCONTENT().length);
	}
}
